package com.xuecheng.media.controller;

import com.xuecheng.api.media.MediaAuditApi;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.vo.MediaAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class MediaAuditController implements MediaAuditApi {

    // 平台机构标识，该标识可以查询所有教学机构课程
    public static final Long OPERATION_FLAG = -99887799L;

    @Autowired
    private MediaService mediaService;

    @PostMapping("m/media/list")
    public PageVO<MediaDTO> queryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {
        Long companyId = SecurityUtil.getCompanyId();
        PageVO<MediaDTO> pageVO = mediaService.queryMediaList(params, model, OPERATION_FLAG);
        return pageVO;
    }

    @PutMapping("m/media/audit")
    public void approveMedia(@RequestBody MediaAuditVO auditVO) {
        MediaDTO dto = MediaConvert.INSTANCE.audit2dto(auditVO);
        mediaService.approveMedia(dto);
    }

    @GetMapping("m/media/preview/{mediaId}")
    public String preViewMedia(@PathVariable("mediaId") Long mediaId) {
        String videoUrl = mediaService.preViewMedia(mediaId);
        return videoUrl;
    }
}
